import { AfterViewInit, Component, Injector, OnDestroy, OnInit } from '@angular/core';
import { ConfigModule } from 'src/app/config.module';
import { Router } from '@angular/router';
import { Subject } from 'rxjs';
import { listAnimation } from '../../../../animations/list.animation';
import { BaseUI } from '../../../../common/base';
import { ServerService } from '../service/server.service';

@Component({
    selector: 'app-server',
    templateUrl: './index.component.html',
    styleUrls: ['./index.component.scss'],
    animations: [listAnimation]
})
export class ServerComponent extends BaseUI implements OnInit, AfterViewInit, OnDestroy {
    onDestroy$: Subject<any> = new Subject<any>();
    loading:boolean = false;

    cpu:any={};
    jvm:any={};
    mem:any={};
    sys:any={};
    sysFiles:any=[];

    constructor(
        public _config: ConfigModule,
        private _router: Router,
        private _injector: Injector,
        public mainService: ServerService
    ) {
        super(_injector);
    }

    ngOnInit() {
        this.server();
    }

    ngAfterViewInit() {}

    ngOnDestroy() {
    }

    server(){
        this.loading = true;
        this.mainService.server().subscribe(res=>{
            this.jvm = res.data.jvm;
            this.cpu = res.data.cpu;
            this.mem = res.data.mem;
            this.sys = res.data.sys;
            this.sysFiles = res.data.sysFiles;
        }).add(()=>this.loading = false);
    }


}
